FROM golang:1.16-alpine3.13 as builder

LABEL org.opencontainers.image.authors="Junyi Xiao <xiaojunyi@foxmail.com>"

ARG CADVISOR_VERSION="v0.39.2"

ENV GOPROXY=https://goproxy.cn

RUN set -ex \
    && sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
    && apk add --update --no-cache git bash make gcc build-base

# RUN git clone --branch ${CADVISOR_VERSION} https://github.com/google/cadvisor.git /go/src/github.com/google/cadvisor
RUN git clone --branch ${CADVISOR_VERSION} https://github.com.cnpmjs.org/google/cadvisor.git /go/src/github.com/google/cadvisor

WORKDIR /go/src/github.com/google/cadvisor

RUN make build

# Image for usage
FROM alpine:3.13

LABEL org.opencontainers.image.authors="Junyi Xiao <xiaojunyi@foxmail.com>"

COPY --from=builder /go/src/github.com/google/cadvisor/cadvisor /usr/bin/cadvisor

EXPOSE 8080
ENTRYPOINT ["/usr/bin/cadvisor", "-logtostderr"]